import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'ro',animated=True)

def init():
    ax.set_xlim(-np.pi,np.pi)
    ax.set_ylim(-1, 1)
    return ln,

def update(frame):
    xdata.append(frame)
    ydata.append(np.sin(frame))
    ln.set_data(xdata, ydata)
    return ln,

def data_gen():

    frame = -np.pi

    step = 2 * np.pi / 90

    while frame < np.pi:
        frame += step
        yield frame

# anim = animation.FuncAnimation(fig, update, frames=np.linspace(-np.pi,np.pi, 360),interval=10,
#                     init_func=init,blit=True)
anim = animation.FuncAnimation(fig, update, frames=data_gen,interval=10,
                    init_func=init,blit=True)

plt.show()

anim.save('C:/Users/18295335197/Desktop/test/GIF/test_animation.gif', writer='Pillow')
